"use strict";
// pages/room/detail.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    show_home: true,
    info: {},
    meetings: [],
    searchtype:[],
    classrelaid: 0,
    month: 0
  },
  input_change: function (e) {
    app.api.api_user_find(e.detail).then(res => {
      this.selectComponent("#searchbar").setSelectVals(res);
    })
  },
  selected: function (e) {
    this.setData({ classrelaid: e.detail.id })
    this.refresh()
  },
  checkboxgroup_change:function(data){
    this.setData({searchtype:data.detail})
    this.refresh()
  },
  exportclass: function () {
    var param = {};
    param['month'] = this.data.month;
    param['modeltype'] = 1;
    param['classrelaid'] = this.data.classrelaid;
    app.api.api_meeting_download(param,this.data.info.name, function () {
      wx.showToast({
        title: '已下载',
        icon: 'none'
      })
    });
  },
  refresh: function () {
    app.api.api_meeting_list({
      month: this.data.month,
      searchtype: this.data.searchtype.join(','),
      classrelaid: this.data.classrelaid
    }).then(res => {
      this.setData({ meetings: res.meetings,info:res.info})
      this.selectComponent("#checkboxgroup").set_data({
        itemsize: this.data.meetings.length,})
    })
  },
  permonth: function () {
    let wval = parseInt(this.data.month) - 1;
    this.setData({ month: wval })
    this.refresh()
  },
  nextmonth: function () {
    let wval = parseInt(this.data.month) + 1;
    this.setData({ month: wval })
    this.refresh()
  },
  
  home: function(){
    app.gotoHome()
  },
  
  detail: function (e) {
    wx.navigateTo({
      url: '../meeting/detail?meeting_id=' + e.currentTarget.id
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    const scene = decodeURIComponent(options.scene)
    let type = ''
    scene.split("&").map(s => {
      if(s.substring(0, s.indexOf("=")) == "type"){
        type = s.substring(s.indexOf("=") + 1, s.length)
      }
    })
    this.setData({ show_home: getCurrentPages().length == 1, searchtype:[type]})
    this.selectComponent("#checkboxgroup").set_data({
      countriesname:[],
      countries:[],
      checksarray: [{ key: 'done', name: '已上' }, { key: 'will', name: '待上' }, { key: 'ydy', name: '1对1' }, { key: 'ttb', name: '团体班' }, { key: 'qjb', name: '秋季班' }, { key: 'aba', name: 'ABA' }, { key: 'xjb', name: '衔接班' }, { key: 'pg', name: '评估' },{key:'teacleave',name:'师假'},{key:'studleave',name:'生假'}]
    })
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.refresh()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    let title = '课程列表'
    if (this.data.info.name) {
      title += " - " + this.data.info.name
    }
    return {
      title: title,
      page: '/pages/meeting/list'
    }
  }
})